<template>
	<view class="home">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular >
			<swiper-item v-for="(i,index) in swiper" :key="i.id">
		<image :src="i.img" ></image>
			</swiper-item>
		</swiper>
		<!-- //导航区 -->
		<view class="nav">
			<view class="nav_item" v-for="(i,index) in navs" :key="index" @click="navitem(i.path)">
				<view :class="i.icon">
				</view>
				<text>{{i.title}}</text>
			</view>
			
		</view>
		<!-- 推荐商品 -->
		<view class="hot_goods">
			<view class="tit">
				推荐商品
			</view>
			<goodsList :goods="goods" @goodsItemClick="goGoodsDetail"></goodsList>
		</view>
		</view>
</template>

<script>
	import goodsList from '../../components/good-list/goods-list'
	export default {
		data() {
			return {
				swiper:[],
				goods:[],
				navs:[
					{
						icon:'iconfont icon-ziyuan',
						title:'黑马超市',
						path:'/pages/goods/goods'
					},
					{
						icon:'iconfont icon-guanyuwomen',
						title:'联系我们',
						path:'/pages/contact/contact'
					},
					{
						icon:'iconfont icon-tupian',
						title:'社区图片',
						path:'/pages/pics/pics'
					},
					{
						icon:'iconfont icon-shipin',
						title:'学习视频',
						path:'/pages/videos/videos'
					}
				]
			}
		},
		components:{
			goodsList
		},
		onLoad() {
		this.getSwipers()
		this.getGoods()
		},
		methods: {
		//获取轮播图数据
		async getSwipers(){
		let res =await this.$myRequest({
				url:'/api/getlunbo',
			})
			
			this.swiper=res.data.message
		},
		//获取热门商品的数据
		async getGoods(){
			let  res= await this.$myRequest({
				url:'/api/getgoods?pageindex=1',
				method:"get"
			})
			
			this.goods=res.data.message
		},
		navitem(u){
			
			uni.navigateTo({
				url:u
			})
		},
		//导航到商品详情页
		goGoodsDetail(id){
			uni.navigateTo({
				url:'/pages/goods-detail/goods-detail?id='+id
			})
		}
		}
	}
</script>

<style lang="less">
	.home{
		swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	.nav{
		display: flex;
		.nav_item{
			width: 25%;
			text-align: center;
			text{
				font-size: 30rpx;
			}
			view{
				width: 120rpx;
				height: 120rpx;
				background-color: #b50e03;
				border-radius: 60rpx;
				margin: 10px auto;
				line-height: 120rpx;
				color: #fff;
				font-size: 60rpx;
			}
		}
	}
	.hot_goods{
		background-color: #eee;
		overflow: hidden;
		margin-top: 8px;
		.tit{
			height: 50px;
			line-height: 50px;
			color: #b50e03;
			text-align: center;
			letter-spacing: 20px;
			background-color: #FFFFFF;
			margin: 5px 0;
			font-size: 45rpx;
		}
	
	
	}
	
</style>
